/* 
 * File:   gridtest.cpp
 * Author: dolphinigle
 *
 * Created on March 11, 2011, 4:23 PM
 */

#include <vector>
#include <string>
#include "gtest/gtest.h"
#include "gtesthelper.hpp"
#include "grid.hpp"
#include "plantablecell.hpp"
#include "game.hpp"

TEST(GridTest, All) {
  Game* game = new Game("Irvan", "test.gag");
  std::vector< std::string > mockmap;
  mockmap.push_back("XXXXX");
  mockmap.push_back("X.OOX");
  mockmap.push_back("XO.OX");
  mockmap.push_back("XXXXX");

  Grid g(game, mockmap);

  EXPECT_EQ(g.getColumn(), (int)mockmap[0].size());
  EXPECT_EQ(g.getRow(), (int)mockmap.size());

  PlantableCell* pc = dynamic_cast<PlantableCell* >(g.getCellAt(2,1));
  EXPECT_FALSE(pc->isWatered());
  pc->water();
  EXPECT_TRUE(pc->isWatered());
  g.advanceTime();
  EXPECT_TRUE(pc->isWatered());
  g.advanceDay();
  EXPECT_FALSE(pc->isWatered());

  for (int i = 0; i < (int)mockmap.size(); ++i) {
    for (int j = 0; j < (int)mockmap[0].size(); ++j) {
      EXPECT_TRUE(g.containsCell(g.getCellAt(j, i)));
      EXPECT_EQ(g.getX(g.getCellAt(j,i)), j);
      EXPECT_EQ(g.getY(g.getCellAt(j,i)), i);
      for (int k = 0; k < (int)mockmap.size(); ++k) {
        for (int l = 0; l < (int)mockmap[0].size(); ++l) {
          if (k == i && l == j) {
            EXPECT_EQ(g.getCellAt(l, k), g.getCellAt(j, i));
          } else {
            EXPECT_NE(g.getCellAt(l, k), g.getCellAt(j, i));
          }
        }
      }
      if (i != 0 && j != 0 && i != (int)mockmap.size()-1
              && j != (int)mockmap[0].size() - 1) {
        for (int k = 0; k < 4; ++k) {
          EXPECT_EQ(g.getCellInFrontOff(g.getCellAt(j, i), Direction(k)),
                  g.getCellAt(j + DirectionNamespace::getDeltaX(Direction(k)),
                              i + DirectionNamespace::getDeltaY(Direction(k))));
        }
      }
    }
  } 

  delete game;
}

